﻿<!DOCTYPE html>
<html lang="en">
<head>
    <title>登录</title>
    <!-- Meta tag Keywords -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <!-- Meta tag Keywords -->
    <!-- css files -->
    <link href="./css/style.css" rel="stylesheet" type="text/css" media="all">
    <script src="./jquery/jquery-3.6.0.js"></script>
<body>
<!--header-->
<div class="agileheader">
    <h1></h1>
</div>
<!--//header-->
<!--main-->
<div class="main-w3l">
    <div class="w3layouts-main">
        <h2>四川大学基线平台</h2>
        <form action="#" method="post">
            <input placeholder="用户名" name="Username" type="username" id="login_username"/>
            <input placeholder="密码" name="Password" type="password" id="login_password"/>
            <!--                    <h6><a href="#">忘记密码?</a></h6>-->

            <div class="clear"></div>
            <input class="btn" type="button" value="登 录" name="login" id="login_button">
        </form>
        <p>还没有账号 ?<a href="./register.html">立即注册</a></p>
    </div>
</div>
<!--//main-->
<!--footer-->
<div class="footer-w3l">
    <p>&copy; Login. All rights reserved | Design by Group8</p>
</div>
<!--//footer-->

</body>
<script>
    $("#login_button").click(function () {
        let login_username = $("#login_username").val();
        let login_password = $("#login_password").val();

        $.ajax({
            url: "/user/login",
            type: "post",
            cache: false,
            data: {
                username: login_username,
                password: login_password
            },
            datatype: "json",
            success: function (response) {
                // alert("2");
                console.log("返回：" + response.code);
                if (response.code === 200) {
                    alert("登录成功！");
                    if (response.data == "user") {
                        window.location.href = "/index_user.html";
                    } else if (response.data == "admin") {
                        window.location.href = "/index.html";
                    }
                }
                if (response.code === 503 || response.code === 501 || response.code === 502){
                    alert("用户名或密码错误！")
                }
                if (response.code === 504){
                    alert("服务器繁忙，请稍后重试！")
                }

            },
            error: function (response) {
                console.log("出错返回：" + response);
                alert("1");
            }
        });
    });
</script>
</html>
